<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Eigen: Matrix manipulation via nullary-expressions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="eigendoxy.css" rel="stylesheet" type="text/css">
<!--  -->
<script type="text/javascript" src="eigen_navtree_hacks.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="Eigen_Silly_Professor_64x64.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname"><a href="http://eigen.tuxfamily.org">Eigen</a>
   &#160;<span id="projectnumber">3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)</span>
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.svg"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('TopicCustomizing_NullaryExpr.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title"><a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors.">Matrix</a> manipulation via nullary-expressions </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The main purpose of the class <a class="el" href="classEigen_1_1CwiseNullaryOp.html" title="Generic expression of a matrix where all coefficients are defined by a functor.">CwiseNullaryOp</a> is to define <em>procedural</em> matrices such as constant or random matrices as returned by the Ones(), Zero(), Constant(), Identity() and Random() methods. Nevertheless, with some imagination it is possible to accomplish very sophisticated matrix manipulation with minimal efforts such that <a class="el" href="TopicNewExpressionType.html">implementing new expression</a> is rarely needed.</p>
<h1><a class="anchor" id="NullaryExpr_Circulant"></a>
Example 1: circulant matrix</h1>
<p>To explore these possibilities let us start with the <em>circulant</em> example of the <a class="el" href="TopicNewExpressionType.html">implementing new expression</a> topic. Let us recall that a circulant matrix is a matrix where each column is the same as the column to the left, except that it is cyclically shifted downwards. For example, here is a 4-by-4 circulant matrix: </p><p class="formulaDsp">
\[ \begin{bmatrix} 1 &amp; 8 &amp; 4 &amp; 2 \\ 2 &amp; 1 &amp; 8 &amp; 4 \\ 4 &amp; 2 &amp; 1 &amp; 8 \\ 8 &amp; 4 &amp; 2 &amp; 1 \end{bmatrix} \]
</p>
<p> A circulant matrix is uniquely determined by its first column. We wish to write a function <code>makeCirculant</code> which, given the first column, returns an expression representing the circulant matrix.</p>
<p>For this exercise, the return type of <code>makeCirculant</code> will be a <a class="el" href="classEigen_1_1CwiseNullaryOp.html" title="Generic expression of a matrix where all coefficients are defined by a functor.">CwiseNullaryOp</a> that we need to instantiate with: 1 - a proper <code>circulant_functor</code> storing the input vector and implementing the adequate coefficient accessor <code>operator(i,j)</code> 2 - a template instantiation of class <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors.">Matrix</a> conveying compile-time information such as the scalar type, sizes, and preferred storage layout.</p>
<p>Calling <code>ArgType</code> the type of the input vector, we can construct the equivalent squared <a class="el" href="classEigen_1_1Matrix.html" title="The matrix class, also used for vectors and row-vectors.">Matrix</a> type as follows:</p>
<div class="fragment"><div class="line"><span class="keyword">template</span>&lt;<span class="keyword">class</span> ArgType&gt;</div>
<div class="line"><span class="keyword">struct </span>circulant_helper {</div>
<div class="line">  <span class="keyword">typedef</span> <a class="code" href="classEigen_1_1Matrix.html">Eigen::Matrix</a>&lt;<span class="keyword">typename</span> ArgType::Scalar,</div>
<div class="line">                 ArgType::SizeAtCompileTime,</div>
<div class="line">                 ArgType::SizeAtCompileTime,</div>
<div class="line">                 <a class="code" href="group__enums.html#ggaacded1a18ae58b0f554751f6cdf9eb13a0103672ae41005ab03b4176c765afd62">Eigen::ColMajor</a>,</div>
<div class="line">                 ArgType::MaxSizeAtCompileTime,</div>
<div class="line">                 ArgType::MaxSizeAtCompileTime&gt; MatrixType;</div>
<div class="line">};</div>
<div class="ttc" id="aclassEigen_1_1Matrix_html"><div class="ttname"><a href="classEigen_1_1Matrix.html">Eigen::Matrix</a></div><div class="ttdoc">The matrix class, also used for vectors and row-vectors.</div><div class="ttdef"><b>Definition:</b> Matrix.h:182</div></div>
<div class="ttc" id="agroup__enums_html_ggaacded1a18ae58b0f554751f6cdf9eb13a0103672ae41005ab03b4176c765afd62"><div class="ttname"><a href="group__enums.html#ggaacded1a18ae58b0f554751f6cdf9eb13a0103672ae41005ab03b4176c765afd62">Eigen::ColMajor</a></div><div class="ttdeci">@ ColMajor</div><div class="ttdef"><b>Definition:</b> Constants.h:321</div></div>
</div><!-- fragment --><p> This little helper structure will help us to implement our <code>makeCirculant</code> function as follows:</p>
<div class="fragment"><div class="line"><span class="keyword">template</span> &lt;<span class="keyword">class</span> ArgType&gt;</div>
<div class="line"><a class="code" href="classEigen_1_1CwiseNullaryOp.html">Eigen::CwiseNullaryOp&lt;circulant_functor&lt;ArgType&gt;</a>, <span class="keyword">typename</span> circulant_helper&lt;ArgType&gt;::MatrixType&gt;</div>
<div class="line">makeCirculant(<span class="keyword">const</span> <a class="code" href="classEigen_1_1MatrixBase.html">Eigen::MatrixBase&lt;ArgType&gt;</a>&amp; <a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>)</div>
<div class="line">{</div>
<div class="line">  <span class="keyword">typedef</span> <span class="keyword">typename</span> circulant_helper&lt;ArgType&gt;::MatrixType MatrixType;</div>
<div class="line">  <span class="keywordflow">return</span> MatrixType::NullaryExpr(<a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>.size(), <a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>.size(), circulant_functor&lt;ArgType&gt;(<a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>.derived()));</div>
<div class="line">}</div>
<div class="ttc" id="aclassEigen_1_1CwiseNullaryOp_html"><div class="ttname"><a href="classEigen_1_1CwiseNullaryOp.html">Eigen::CwiseNullaryOp</a></div><div class="ttdoc">Generic expression of a matrix where all coefficients are defined by a functor.</div><div class="ttdef"><b>Definition:</b> CwiseNullaryOp.h:63</div></div>
<div class="ttc" id="aclassEigen_1_1MatrixBase_html"><div class="ttname"><a href="classEigen_1_1MatrixBase.html">Eigen::MatrixBase</a></div><div class="ttdoc">Base class for all dense matrices, vectors, and expressions.</div><div class="ttdef"><b>Definition:</b> MatrixBase.h:52</div></div>
<div class="ttc" id="anamespaceEigen_html_aa539408a09481d35961e11ee78793db1"><div class="ttname"><a href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">Eigen::arg</a></div><div class="ttdeci">const Eigen::CwiseUnaryOp&lt; Eigen::internal::scalar_arg_op&lt; typename Derived::Scalar &gt;, const Derived &gt; arg(const Eigen::ArrayBase&lt; Derived &gt; &amp;x)</div></div>
</div><!-- fragment --><p> As usual, our function takes as argument a <code><a class="el" href="classEigen_1_1MatrixBase.html" title="Base class for all dense matrices, vectors, and expressions.">MatrixBase</a></code> (see this <a class="el" href="TopicFunctionTakingEigenTypes.html">page</a> for more details). Then, the <a class="el" href="classEigen_1_1CwiseNullaryOp.html" title="Generic expression of a matrix where all coefficients are defined by a functor.">CwiseNullaryOp</a> object is constructed through the <a class="el" href="classEigen_1_1DenseBase.html#a3340c9b997f5b53a0131cf927f93b54c">DenseBase::NullaryExpr</a> static method with the adequate runtime sizes.</p>
<p>Then, we need to implement our <code>circulant_functor</code>, which is a straightforward exercise:</p>
<div class="fragment"><div class="line"><span class="keyword">template</span>&lt;<span class="keyword">class</span> ArgType&gt;</div>
<div class="line"><span class="keyword">class </span>circulant_functor {</div>
<div class="line">  <span class="keyword">const</span> ArgType &amp;m_vec;</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">  circulant_functor(<span class="keyword">const</span> ArgType&amp; <a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>) : m_vec(<a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>) {}</div>
<div class="line"> </div>
<div class="line">  <span class="keyword">const</span> <span class="keyword">typename</span> ArgType::Scalar&amp; operator() (<a class="code" href="namespaceEigen.html#a62e77e0933482dafde8fe197d9a2cfde">Eigen::Index</a> row, <a class="code" href="namespaceEigen.html#a62e77e0933482dafde8fe197d9a2cfde">Eigen::Index</a> col)<span class="keyword"> const </span>{</div>
<div class="line">    <a class="code" href="namespaceEigen.html#a62e77e0933482dafde8fe197d9a2cfde">Eigen::Index</a> index = row - col;</div>
<div class="line">    <span class="keywordflow">if</span> (index &lt; 0) index += m_vec.size();</div>
<div class="line">    <span class="keywordflow">return</span> m_vec(index);</div>
<div class="line">  }</div>
<div class="line">};</div>
<div class="ttc" id="anamespaceEigen_html_a62e77e0933482dafde8fe197d9a2cfde"><div class="ttname"><a href="namespaceEigen.html#a62e77e0933482dafde8fe197d9a2cfde">Eigen::Index</a></div><div class="ttdeci">EIGEN_DEFAULT_DENSE_INDEX_TYPE Index</div><div class="ttdoc">The Index type as used for the API.</div><div class="ttdef"><b>Definition:</b> Meta.h:59</div></div>
</div><!-- fragment --><p> We are now all set to try our new feature:</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">Eigen::VectorXd</a> vec(4);</div>
<div class="line">  vec &lt;&lt; 1, 2, 4, 8;</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">Eigen::MatrixXd</a> mat;</div>
<div class="line">  mat = makeCirculant(vec);</div>
<div class="line">  std::cout &lt;&lt; mat &lt;&lt; std::endl;</div>
<div class="line">}</div>
</div><!-- fragment --><p>If all the fragments are combined, the following output is produced, showing that the program works as expected:</p>
<div class="fragment"><div class="line">1 8 4 2</div>
<div class="line">2 1 8 4</div>
<div class="line">4 2 1 8</div>
<div class="line">8 4 2 1</div>
</div><!-- fragment --><p>This implementation of <code>makeCirculant</code> is much simpler than <a class="el" href="TopicNewExpressionType.html">defining a new expression</a> from scratch.</p>
<h1><a class="anchor" id="NullaryExpr_Indexing"></a>
Example 2: indexing rows and columns</h1>
<p>The goal here is to mimic MatLab's ability to index a matrix through two vectors of indices referencing the rows and columns to be picked respectively, like this:</p>
<div class="fragment"><div class="line">A =</div>
<div class="line"> 7  9 -5 -3</div>
<div class="line">-2 -6  1  0</div>
<div class="line"> 6 -3  0  9</div>
<div class="line"> 6  6  3  9</div>
<div class="line"> </div>
<div class="line">A([1 2 1], [3 2 1 0 0 2]) =</div>
<div class="line"> 0  1 -6 -2 -2  1</div>
<div class="line"> 9  0 -3  6  6  0</div>
<div class="line"> 0  1 -6 -2 -2  1</div>
</div><!-- fragment --><p> To this end, let us first write a nullary-functor storing references to the input matrix and to the two arrays of indices, and implementing the required <code>operator()(i,j)</code>:</p>
<div class="fragment"><div class="line"><span class="keyword">template</span>&lt;<span class="keyword">class</span> ArgType, <span class="keyword">class</span> RowIndexType, <span class="keyword">class</span> ColIndexType&gt;</div>
<div class="line"><span class="keyword">class </span>indexing_functor {</div>
<div class="line">  <span class="keyword">const</span> ArgType &amp;m_arg;</div>
<div class="line">  <span class="keyword">const</span> RowIndexType &amp;m_rowIndices;</div>
<div class="line">  <span class="keyword">const</span> ColIndexType &amp;m_colIndices;</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">  <span class="keyword">typedef</span> <a class="code" href="classEigen_1_1Matrix.html">Eigen::Matrix</a>&lt;<span class="keyword">typename</span> ArgType::Scalar,</div>
<div class="line">                 RowIndexType::SizeAtCompileTime,</div>
<div class="line">                 ColIndexType::SizeAtCompileTime,</div>
<div class="line">                 ArgType::Flags&amp;<a class="code" href="group__flags.html#gae4f56c2a60bbe4bd2e44c5b19cbe8762">Eigen::RowMajorBit</a>?<a class="code" href="group__enums.html#ggaacded1a18ae58b0f554751f6cdf9eb13a77c993a8d9f6efe5c1159fb2ab07dd4f">Eigen::RowMajor</a>:<a class="code" href="group__enums.html#ggaacded1a18ae58b0f554751f6cdf9eb13a0103672ae41005ab03b4176c765afd62">Eigen::ColMajor</a>,</div>
<div class="line">                 RowIndexType::MaxSizeAtCompileTime,</div>
<div class="line">                 ColIndexType::MaxSizeAtCompileTime&gt; MatrixType;</div>
<div class="line"> </div>
<div class="line">  indexing_functor(<span class="keyword">const</span> ArgType&amp; <a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>, <span class="keyword">const</span> RowIndexType&amp; row_indices, <span class="keyword">const</span> ColIndexType&amp; col_indices)</div>
<div class="line">    : m_arg(<a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>), m_rowIndices(row_indices), m_colIndices(col_indices)</div>
<div class="line">  {}</div>
<div class="line"> </div>
<div class="line">  <span class="keyword">const</span> <span class="keyword">typename</span> ArgType::Scalar&amp; operator() (<a class="code" href="namespaceEigen.html#a62e77e0933482dafde8fe197d9a2cfde">Eigen::Index</a> row, <a class="code" href="namespaceEigen.html#a62e77e0933482dafde8fe197d9a2cfde">Eigen::Index</a> col)<span class="keyword"> const </span>{</div>
<div class="line">    <span class="keywordflow">return</span> m_arg(m_rowIndices[row], m_colIndices[col]);</div>
<div class="line">  }</div>
<div class="line">};</div>
<div class="ttc" id="agroup__enums_html_ggaacded1a18ae58b0f554751f6cdf9eb13a77c993a8d9f6efe5c1159fb2ab07dd4f"><div class="ttname"><a href="group__enums.html#ggaacded1a18ae58b0f554751f6cdf9eb13a77c993a8d9f6efe5c1159fb2ab07dd4f">Eigen::RowMajor</a></div><div class="ttdeci">@ RowMajor</div><div class="ttdef"><b>Definition:</b> Constants.h:323</div></div>
<div class="ttc" id="agroup__flags_html_gae4f56c2a60bbe4bd2e44c5b19cbe8762"><div class="ttname"><a href="group__flags.html#gae4f56c2a60bbe4bd2e44c5b19cbe8762">Eigen::RowMajorBit</a></div><div class="ttdeci">const unsigned int RowMajorBit</div><div class="ttdef"><b>Definition:</b> Constants.h:68</div></div>
</div><!-- fragment --><p> Then, let's create an <code>indexing(A,rows,cols)</code> function creating the nullary expression:</p>
<div class="fragment"><div class="line"><span class="keyword">template</span> &lt;<span class="keyword">class</span> ArgType, <span class="keyword">class</span> RowIndexType, <span class="keyword">class</span> ColIndexType&gt;</div>
<div class="line"><a class="code" href="classEigen_1_1CwiseNullaryOp.html">Eigen::CwiseNullaryOp&lt;indexing_functor&lt;ArgType,RowIndexType,ColIndexType&gt;</a>, <span class="keyword">typename</span> indexing_functor&lt;ArgType,RowIndexType,ColIndexType&gt;::MatrixType&gt;</div>
<div class="line">mat_indexing(<span class="keyword">const</span> <a class="code" href="classEigen_1_1MatrixBase.html">Eigen::MatrixBase&lt;ArgType&gt;</a>&amp; <a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>, <span class="keyword">const</span> RowIndexType&amp; row_indices, <span class="keyword">const</span> ColIndexType&amp; col_indices)</div>
<div class="line">{</div>
<div class="line">  <span class="keyword">typedef</span> indexing_functor&lt;ArgType,RowIndexType,ColIndexType&gt; Func;</div>
<div class="line">  <span class="keyword">typedef</span> <span class="keyword">typename</span> Func::MatrixType MatrixType;</div>
<div class="line">  <span class="keywordflow">return</span> MatrixType::NullaryExpr(row_indices.size(), col_indices.size(), Func(<a class="code" href="namespaceEigen.html#aa539408a09481d35961e11ee78793db1">arg</a>.derived(), row_indices, col_indices));</div>
<div class="line">}</div>
</div><!-- fragment --><p> Finally, here is an example of how this function can be used:</p>
<div class="fragment"><div class="line">  <a class="code" href="classEigen_1_1Matrix.html">Eigen::MatrixXi</a> A = <a class="code" href="classEigen_1_1DenseBase.html#ae814abb451b48ed872819192dc188c19">Eigen::MatrixXi::Random</a>(4,4);</div>
<div class="line">  <a class="code" href="classEigen_1_1Array.html">Eigen::Array3i</a> ri(1,2,1);</div>
<div class="line">  <a class="code" href="classEigen_1_1Array.html">Eigen::ArrayXi</a> ci(6); ci &lt;&lt; 3,2,1,0,0,2;</div>
<div class="line">  <a class="code" href="classEigen_1_1Matrix.html">Eigen::MatrixXi</a> B = mat_indexing(A, ri, ci);</div>
<div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;A =&quot;</span> &lt;&lt; std::endl;</div>
<div class="line">  std::cout &lt;&lt; A &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;A([&quot;</span> &lt;&lt; ri.<a class="code" href="classEigen_1_1DenseBase.html#a43cbcd866a0737eb56642c2e992f0afd">transpose</a>() &lt;&lt; <span class="stringliteral">&quot;], [&quot;</span> &lt;&lt; ci.transpose() &lt;&lt; <span class="stringliteral">&quot;]) =&quot;</span> &lt;&lt; std::endl;</div>
<div class="line">  std::cout &lt;&lt; B &lt;&lt; std::endl;</div>
<div class="ttc" id="aclassEigen_1_1Array_html"><div class="ttname"><a href="classEigen_1_1Array.html">Eigen::Array</a></div><div class="ttdoc">General-purpose arrays with easy API for coefficient-wise operations.</div><div class="ttdef"><b>Definition:</b> Array.h:49</div></div>
<div class="ttc" id="aclassEigen_1_1DenseBase_html_a43cbcd866a0737eb56642c2e992f0afd"><div class="ttname"><a href="classEigen_1_1DenseBase.html#a43cbcd866a0737eb56642c2e992f0afd">Eigen::DenseBase::transpose</a></div><div class="ttdeci">TransposeReturnType transpose()</div><div class="ttdef"><b>Definition:</b> Transpose.h:184</div></div>
<div class="ttc" id="aclassEigen_1_1DenseBase_html_ae814abb451b48ed872819192dc188c19"><div class="ttname"><a href="classEigen_1_1DenseBase.html#ae814abb451b48ed872819192dc188c19">Eigen::DenseBase::Random</a></div><div class="ttdeci">static const RandomReturnType Random()</div><div class="ttdef"><b>Definition:</b> Random.h:114</div></div>
</div><!-- fragment --><p> This straightforward implementation is already quite powerful as the row or column index arrays can also be expressions to perform offsetting, modulo, striding, reverse, etc.</p>
<div class="fragment"><div class="line">  B =  mat_indexing(A, ri+1, ci);</div>
<div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;A(ri+1,ci) =&quot;</span> &lt;&lt; std::endl;</div>
<div class="line">  std::cout &lt;&lt; B &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="line">  B =  mat_indexing(A, <a class="code" href="classEigen_1_1DenseBase.html#a1c6d1dbfeb9f6491173a83eb44e14c1d">Eigen::ArrayXi::LinSpaced</a>(13,0,12).unaryExpr([](<span class="keywordtype">int</span> x){<span class="keywordflow">return</span> x%4;}), <a class="code" href="classEigen_1_1DenseBase.html#a1c6d1dbfeb9f6491173a83eb44e14c1d">Eigen::ArrayXi::LinSpaced</a>(4,0,3));</div>
<div class="line">  std::cout &lt;&lt; <span class="stringliteral">&quot;A(ArrayXi::LinSpaced(13,0,12).unaryExpr([](int x){return x%4;}), ArrayXi::LinSpaced(4,0,3)) =&quot;</span> &lt;&lt; std::endl;</div>
<div class="line">  std::cout &lt;&lt; B &lt;&lt; std::endl &lt;&lt; std::endl;</div>
<div class="ttc" id="aclassEigen_1_1DenseBase_html_a1c6d1dbfeb9f6491173a83eb44e14c1d"><div class="ttname"><a href="classEigen_1_1DenseBase.html#a1c6d1dbfeb9f6491173a83eb44e14c1d">Eigen::DenseBase::LinSpaced</a></div><div class="ttdeci">static EIGEN_DEPRECATED const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar &amp;low, const Scalar &amp;high)</div><div class="ttdef"><b>Definition:</b> CwiseNullaryOp.h:246</div></div>
</div><!-- fragment --><p> and the output is:</p>
<div class="fragment"><div class="line">A(ri+1,ci) =</div>
<div class="line"> 9  0 -3  6  6  0</div>
<div class="line"> 9  3  6  6  6  3</div>
<div class="line"> 9  0 -3  6  6  0</div>
<div class="line"> </div>
<div class="line">A(ArrayXi::LinSpaced(13,0,12).unaryExpr([](int x){return x%4;}), ArrayXi::LinSpaced(4,0,3)) =</div>
<div class="line"> 7  9 -5 -3</div>
<div class="line">-2 -6  1  0</div>
<div class="line"> 6 -3  0  9</div>
<div class="line"> 6  6  3  9</div>
<div class="line"> 7  9 -5 -3</div>
<div class="line">-2 -6  1  0</div>
<div class="line"> 6 -3  0  9</div>
<div class="line"> 6  6  3  9</div>
<div class="line"> 7  9 -5 -3</div>
<div class="line">-2 -6  1  0</div>
<div class="line"> 6 -3  0  9</div>
<div class="line"> 6  6  3  9</div>
<div class="line"> 7  9 -5 -3</div>
<div class="line"> </div>
</div><!-- fragment --></div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Thu Apr 21 2022 13:07:55 for Eigen by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
